#include<bits/stdc++.h>
using namespace std;
const int N=1e6+99;
int n,p[N],pos[N],len[2*N];
int f[N],mn[N],mx[N],nxtmn[N],nxtmx[N];
int find(int x){
    if(f[x]==x) return x;
    return f[x]=find(f[x]);
}
void add(int x,int y){
    if((x&1)==0) return;
    x=x/2+1; y=y/2+1;
    x=find(x); y=find(y);
    if(x==y) return;
    f[y]=x;
    mn[x]=min(mn[x],mn[y]); mx[x]=max(mx[x],mx[y]);
    nxtmn[x]=min(nxtmn[x],nxtmn[y]); nxtmx[x]=max(nxtmx[x],nxtmx[y]);
    return;
}
int q[N],pq[N],cnt,lim[N],ans[N];
bool cmp(int A,int B){
    return mn[A]<mn[B];
}
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>p[i],p[i]++,pos[p[i]]=i;
    int b=0;
    for(int i=1;i<=2*n-1;i++){
        cin>>len[i];
        b|=((i&1)^(len[i]&1));
        if((i&1)==0&&len[i]==0) len[i]=1;
        if(i+len[i]-1>2*n-1||len[i]>i) b=1;
    }
    if(b){
        cout<<"-1"<<'\n';
        return;
    }
    pos[n+1]=0; f[n+1]=n+1;
    for(int i=1;i<=n;i++) f[i]=i,mn[i]=mx[i]=pos[i],nxtmn[i]=nxtmx[i]=pos[i+1];
    int d=0,r=0,l;
    for(int i=1;i<=2*n-1;i++){
        if(i<=r){
            l=2*d-i;
            if(len[i]!=len[l]&&len[i]<=r-i+1&&len[l]<=r-i+1){
                cout<<"-1"<<'\n';
                return;
            }
        }
        if(i+len[i]-1>=r){
            d=i; r=max(r,i);
            while(r<=i+len[i]-1&&2*i-r>=1){
                add(r,2*i-r);
                r++;
            }
            r--;
        }
    }
    cnt=0;
    for(int i=1;i<=n;i++)
        if(find(i)==i)
            q[++cnt]=i;
    sort(q+1,q+cnt+1,cmp);
    r=0;
    for(int i=1;i<=cnt;i++){
        if(mn[q[i]]<=r) add(2*q[i]-1,2*q[i-1]-1);
        r=max(r,mx[q[i]]);
    }
    int cntt=0;
    for(int i=1;i<=cnt;i++)
        if(find(q[i])==q[i])
            q[++cntt]=q[i],pq[q[cntt]]=cntt;
    cnt=cntt;
//    for(int i=1;i<=cnt;i++)
//        cout<<q[i]<<" ";
//    cout<<'\n';
    int fl,fr;
    for(int i=1;i<=n+1;i++) lim[i]=cnt;
    for(int i=1;i<=2*n-1;i++){
        l=i-len[i]-1; r=i+len[i]+1;
        if((i&1)==0&&len[i]==1) l++,r--;
        if(l<=0||r>=2*n) continue;
        l=l/2+1; r=r/2+1;
        fl=find(l); fr=find(r);
        if(pq[fl]<pq[fr])
            lim[pq[fl]]=min(lim[pq[fl]],pq[fr]-1);
        else
            lim[pq[fr]]=min(lim[pq[fr]],pq[fl]-1);
    }
//    cout<<mn[q[1]]<<" "<<mx[q[1]]<<endl;
    int nowlim=0,nowmx=0,val=0;
    for(int i=1;i<=cnt;i++)
        if(lim[i]<i){
            cout<<"-1"<<'\n';
            return;
        }
    for(int i=1;i<=cnt;i++){
        if(i>nowlim||nxtmn[q[i]]<nowmx){
            ans[i]=++val;
            nowlim=lim[i]; nowmx=nxtmx[q[i]];
        }
        else{
            ans[i]=val;
            nowlim=min(nowlim,lim[i]);
            nowmx=max(nowmx,nxtmx[q[i]]);
        }
    }
    if(val>26){
        cout<<"-1"<<'\n';
        return;
    }
    for(int i=1;i<=n;i++){
        find(i);
        cout<<(char)(ans[pq[f[i]]]-1+'a');
    }
    cout<<'\n';
    return;
}
int main(){
    freopen("string.in","r",stdin);
    freopen("string.out","w",stdout);
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int T; cin>>T;
    while(T--) solve();
//    cerr<<fixed<<setprecision(3)<<(double)clock()/CLOCKS_PER_SEC;
    return 0;
}